#ifndef DATAMODEL_H
#define DATAMODEL_H

#include <QObject>
#include <QtSql/QtSql>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>

class dataModel
{
public:
    dataModel();
    ~dataModel();

private:
    QSqlDatabase mainDB;

    bool dateIsUpdated;

    QStringList recordList;
    int recordListIndex;

    QString beginDate;
    QString endDate;

    bool refreshed;

public:
    int recordTotal() {return recordList.length();}
    int recordIndex() {return recordListIndex + 1;}

    void createDefaultTable();

    int readAllData();
    int findBySN(QString);
    int next();
    int pre();
    void getCurrentRecordInfo(QStringList &result);
    void getCurrentRecordData(int rowID, QStringList &result);

    void deleteAll();
    void deleteBySN(QString SN);

    bool saveErrorData(QStringList strList);
    int newRecord(QString,QString,QString,QString,QString,QString);

    void setDateRange(QString a, QString b){beginDate = a; endDate = b;dateIsUpdated=true;}

    void printTheRecord( QString SN );

    void readRecord(int index, QStringList &record);

    bool isRefreshed(){return refreshed;}
};

#endif // DATAMODEL_H
